<?php

namespace app\common\model;


use think\Model;

class OrderLog extends  Model
{
    const CREATE_ORDER      = 1;  //创建订单
    const PAY_YES           = 2;  //订单支付成功
    const ORDER_USE         = 3;  //订单使用
    const ORDER_CANCAL      = 4;  //订单取消
    const ORDER_EXPIRE      = 5;  //订单过期
    const ORDER_USE_PARTIAL = 6;  //订单部分使用
    const ORDER_OVER        = 7;  //订单已完结
    const ORDER_REFUND      = 8;  //订单退款
    const ORDER_CHANG       = 9;  //改签
    const ORDER_CONFIRM     = 10; //商家确认

    protected $_type = [
        1  => '创建订单',
        2  => '支付成功',
        3  => '订单使用',
        4  => '订单取消',
        5  => '订单过期',
        6  => '部分验证',
        7  => '订单完结',
        8  => '订单退款',
        9  => '改签时间',
        10 => '商家确认'
    ];

    
    public function getCtimeAttr($value)
    {
        return $value && is_numeric($value) ? datetime($value) : $value;
    }

    /**
     * [createLog 添加订单日志]
     * @Author   ZhouYunpeng
     * @DateTime 2020-12-31
     * @param    [type]      $order_id [description]
     * @param    [type]      $type     [description]
     * @return   [type]                [description]
     */
    public function createLog($order_id,$type,$msg)
    {
        $log = ['order_id' => $order_id,'type'=> $type,'create_time' => time()];
        $this->allowField(true)->save($log);
    }

    /**
     * [getOrderLog 订单操作日志]
     * @Author   ZhouYunpeng
     * @DateTime 2020-12-31
     * @param    [type]      $order_id [description]
     * @return   [type]                [description]
     */
    public function getOrderLog($order_id)
    {
        $log_list = $this->where('order_id',$order_id)->select();
        foreach ($log_list as $value){
            $value['type'] = $this->_type[$value['type']];
        }
        return $log_list;
    }
   
    public function getLog($where = [])
    {
        $list = $this->where($where)->select();
        foreach ($list as $value){
            $value['type'] = $this->_type[$value['type']];
        }
        return $list;
    }


}